package com.cat.binaryTree;

/**
 *   @description https://leetcode.cn/problems/merge-in-between-linked-lists/description/
 *   @author 曲大人的喵
 *   @create 2025/9/10 18:29
 *   @since JDK17
 */

public class Solution12 {
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode p = list1, q = list1;
        ListNode end = list2;
        while (end.next != null) {
            end = end.next;
        }
        for (int i = 0; i <= b; i++, p = p.next) {
            if (i == a - 1) {
                q = p;
            }
        }
        q.next = list2;
        end.next = p;
        return list1;
    }
}
